import Vue from 'vue'
import VueRouter from 'vue-router'
// import login from '../components/login.vue'
const login = () => import( /* webpackChunkName: 'login_home_welcome' */ '../components/login.vue')

// import home from '../components/home.vue'
const home = () => import( /* webpackChunkName: 'login_home_welcome' */ '../components/home.vue')

// import welcome from '../components/welcome.vue'
const welcome = () => import( /* webpackChunkName: 'login_home_welcome' */ '../components/welcome.vue')


// import user from '../components/user/user.vue'
const user = () => import( /* webpackChunkName: 'user_rights_roles' */ '../components/user/user.vue')
// import { push } from 'core-js/fn/array'
// import { component } from 'vue/types/umd'
// import Rights from '../components/power/rights.vue'
const Rights = () => import( /* webpackChunkName: 'user_rights_roles' */ '../components/power/rights.vue')
// import Roles from '../components/power/roles.vue'
const Roles = () => import( /* webpackChunkName: 'user_rights_roles' */ '../components/power/roles.vue')


// import Cate from '../components/goods/cate.vue'
const Cate = () => import( /* webpackChunkName: 'cate_params' */ '../components/goods/cate.vue')

// import Params from '../components/goods/params.vue'
const Params = () => import( /* webpackChunkName: 'cate_params' */ '../components/goods/params.vue')


// import goodsList from '../components/goods/List.vue'
const goodsList = () => import( /* webpackChunkName: 'goodslist_goodsadd' */ '../components/goods/List.vue')

// import goodsadd from '../components/goods/add.vue'
const goodsadd = () => import( /* webpackChunkName: 'goodslist_goodsadd' */ '../components/goods/add.vue')


// import Order from '../components/order/Order.vue'
const Order = () => import( /* webpackChunkName: 'Order_report' */ '../components/order/Order.vue')

// import Report from '../components/report/Report.vue'
const Report = () => import( /* webpackChunkName: 'Order_report' */ '../components/report/Report.vue')


Vue.use(VueRouter)

const routes = [{
    path: '/login',
    component: login
  },
  {
    path: '/',
    redirect: '/login'
  },

  {
    path: '/home',
    component: home,
    redirect: '/welcome',
    children: [{
        path: '/welcome',
        component: welcome
      },
      {
        path: '/users',
        component: user
      },
      {
        path: '/rights',
        component: Rights
      },
      {
        path: '/roles',
        component: Roles
      },
      {
        path: '/categories',
        component: Cate
      },
      {
        path: '/params',
        component: Params
      },
      {
        path: '/goods',
        component: goodsList
      },
      {
        path: '/goods/add',
        component: goodsadd
      },
      {
        path: '/Orders',
        component: Order
      }, {
        path: '/reports',
        component: Report
      }
    ]
  },



]

const router = new VueRouter({
  routes
})


router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()

  const getToken = window.sessionStorage.getItem('token')
  if (!getToken) return next('/login')
  next()

})

export default router